package com.itheima.appserver;

import com.baidu.aip.face.AipFace;
import com.itheima.autoconfig.template.FaceTemplate;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = AppServerApplication.class)
public class test2 {
    @Autowired
    private FaceTemplate faceTemplate;


    @Test
    public void test() {
        faceTemplate.face
            ("https://tanhuawsj.oss-cn-shenzhen.aliyuncs.com/2022/03/24/1b918df0-22a6-4b0f-8202-33da2292daf3.jpg");
    }

    //设置APPID/AK/SK
    public static final String APP_ID = "25830428";
    public static final String API_KEY = "epd2neAUj78OaKjiDUtniaMP";
    public static final String SECRET_KEY = "6pKaePN3gcMYVDCkjawVAAptuFBh3AVG";

    public static void main(String[] args) {
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
        // 调用接口
        String image = "https://tanhuawsj.oss-cn-shenzhen.aliyuncs.com/2022/03/23/3f268860-3b4e-43c4-86fc-5ccfeaf7ea29.jpg";
        String imageType = "URL";
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "LOW");
        // 人脸检测
        JSONObject res = client.detect(image, imageType, options);
        System.out.println(res.toString(2));

    }
}
